package com.hospital.hospital.service.impl;

import com.hospital.hospital.bean.Department;
import com.hospital.hospital.mapper.DepartmentMapper;
import com.hospital.hospital.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;


@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;



    @Override
    public List<Department> queryAll() throws Exception {
        List<Department> departments = null;
        departments = departmentMapper.queryAll();
        return departments;
    }

    @Override
    public void addDep(Department department) throws Exception {
        Timestamp createTime = new Timestamp(new Date().getTime());
        department.setCreateTime(createTime);
        department.setState(1);
        System.out.println(department);
        departmentMapper.insertDep(department);
    }

    @Override
    public void deleteDep(Integer departmentId) throws Exception {
        departmentMapper.deleteDep(departmentId);
    }

    @Override
    public List<Department> queryLike(String likestr) throws Exception {
        List<Department> departments = departmentMapper.queryLike(likestr);
        return departments;
    }

    @Override
    public void qh(Integer departmentId) throws Exception {
        Department department = departmentMapper.queryById(departmentId);
        Integer state = 1 - department.getState();
        department.setState(state);

        departmentMapper.qh(department);
    }

    @Override
    public Department queryById(Integer departmentId) throws Exception {
        Department department = departmentMapper.queryById(departmentId);
        return department;
    }

    @Override
    public void set(Department department) throws Exception {
        Department department1 = departmentMapper.queryById(department.getDepartmentId());
        Timestamp createTime = new Timestamp(new Date().getTime());
        department1.setModificationTime(createTime);
        department1.setModifier(department.getModifier());
        department1.setState(1);
        departmentMapper.set(department1);
    }

    @Override
    public List<Department> queryByPage(Integer page) {
        Integer p = (page -1)*4;
        List<Department> departments = departmentMapper.queryByPage(p);
        return departments;
    }
}
